<template>
  <view>
    <u-tabbar :list="uTabbarList" height="100"></u-tabbar>
    <u-modal v-model="isRoleError" :show-confirm-button="false" :show-title="false" border-radius="20">
      <view class="w-full flex flex-column align-center p-lr-50">
        <view class="lh-center color-333 fz-30 fw-700 p-tb-42 border-bottom-CCCCCC w-full">
          <text>您的账户异常，请返回登录页重试</text>
        </view>
        <view class="flex align-center justify-center m-tb-50">
          <view class="bg-2D8CF0 w-120 h-60 color-fff fz-28 text-center lh-60 br-5" @tap="handleLogout">
            <text>确定</text>
          </view>
        </view>
      </view>
    </u-modal>
  </view>
</template>

<script>
export default {
  name: "CustomUTabbar",
  data(){
    return {
      isRoleError: false
    }
  },
  created(){
    if (!this.$auth.hasRoleOr(['admin','co-admin', 'manager', 'engineer', 'head-nurse', 'nurse'])){
      this.isRoleError = true
    }
  },
  computed:{
    uTabbarList() {
      // 管理原或经理
      if(this.$auth.hasRoleOr(['admin','co-admin', 'manager'])){
        return [
          {
            iconPath: "/static/images/tabbar/home.png",
            selectedIconPath: "/static/images/tabbar/home_.png",
            pagePath: "/pages/tabbar/home/home",
            text: "首页",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/work.png",
            selectedIconPath: "/static/images/tabbar/work_.png",
            pagePath: "/pages/tabbar/work/work",
            text: "巡检",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/upkeep.png",
            selectedIconPath: "/static/images/tabbar/upkeep_.png",
            pagePath: "/pages/tabbar/maintenance/maintenance",
            text: "保养",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/fix.png",
            selectedIconPath: "/static/images/tabbar/fix_.png",
            pagePath: "/pages/tabbar/repair/repair",
            text: "维修",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/mine.png",
            selectedIconPath: "/static/images/tabbar/mine_.png",
            pagePath: "/pages/tabbar/mine/mine",
            text: "我的",
            isDot: false,
            customIcon: false,
          },
        ]
      }
      //工程师
      if(this.$auth.hasRole('engineer')){
        return  [
          {
            iconPath: "/static/images/tabbar/computer.png",
            selectedIconPath: "/static/images/tabbar/computer_.png",
            pagePath: "/pages/tabbar/home/home",
            text: "工作台",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/work.png",
            selectedIconPath: "/static/images/tabbar/work_.png",
            pagePath: "/pages/tabbar/work/work",
            text: "巡检",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/upkeep.png",
            selectedIconPath: "/static/images/tabbar/upkeep_.png",
            pagePath: "/pages/tabbar/maintenance/maintenance",
            text: "保养",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/fix.png",
            selectedIconPath: "/static/images/tabbar/fix_.png",
            pagePath: "/pages/tabbar/repair/repair",
            text: "维修",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/mine.png",
            selectedIconPath: "/static/images/tabbar/mine_.png",
            pagePath: "/pages/tabbar/mine/mine",
            text: "我的",
            isDot: false,
            customIcon: false,
          },
        ]
      }
      //护士或护士长
      if(this.$auth.hasRoleOr(['head-nurse', 'nurse'])){
        return [
          {
            iconPath: "/static/images/tabbar/work.png",
            selectedIconPath: "/static/images/tabbar/work_.png",
            pagePath: "/pages/tabbar/work/work",
            text: "巡检",
            isDot: false,
            customIcon: false,
          },
          {
            iconPath: "/static/images/tabbar/mine.png",
            selectedIconPath: "/static/images/tabbar/mine_.png",
            pagePath: "/pages/tabbar/mine/mine",
            text: "我的",
            isDot: false,
            customIcon: false,
          }]
      }
      return []
    },
  },
  methods: {
    //登出操作
    handleLogout(){
      this.isRoleError = false
      this.$store.dispatch('LogOut').then(() => {
        this.$tab.reLaunch('/pages/login')
      })
    }
  }
}
</script>

<style scoped>

</style>
